import 'package:flutter/material.dart';

import 'controllers/homePageController.dart';
import 'controllers/businessListPageController.dart';
import 'controllers/communityPageController.dart';
import 'controllers/userPageController.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: RootPage(),
    );
  }
}

class RootPage extends StatefulWidget {
  RootPage({Key key}): super(key: key);

  @override
  _RootPageState createState()=> _RootPageState();
}

class _RootPageState extends State<RootPage> {

  int _currentIndex = 0;
  final List<Widget> _childPage = [HomePageWidget(),BusinessListPageWidget(),CommunityPageWidget(),UserPageWidget()];
  final List<BottomNavigationBarItem> _barItems = <BottomNavigationBarItem>[
    BottomNavigationBarItem(icon: Icon(Icons.home),label: '首页'),
    BottomNavigationBarItem(icon: Icon(Icons.list),label: '附近'),
    BottomNavigationBarItem(icon: Icon(Icons.find_in_page),label: '发现'),
    BottomNavigationBarItem(icon: Icon(Icons.people),label: '我的')
  ];


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext content){
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        items: _barItems,
      ),
      body: _childPage[_currentIndex],
    );
  }

  void onTabTapped(int index){
    setState(() {
      _currentIndex = index;
    });
  }
}